<?php
/**
 * Copyright (c) 2012, xxworkshop Inc.
 * All rights reserved.
 *
 * Created by BrocheXu on 2014.11.6
 */
require_once 'accesstokenmanager.class.php';

class MenuManager {
	const MenuUrl = 'https://api.weixin.qq.com/cgi-bin/menu/';

	private $accessTokenManager;
	
	public function __construct($appid, $appsecret) {
		$this->accessTokenManager = new AccessTokenManager($appid, $appsecret);
	}
	
	public function getMenu() {
		$url = self::MenuUrl.'get?access_token='.$this->accessTokenManager->getToken();
		return json_decode(file_get_contents($url), true);
	}
	
	public function createMenu($menu) {
		$url = self::MenuUrl.'create?access_token='.$this->accessTokenManager->getToken();
		$options['http'] = array('method'=>'POST', 'content'=>$menu);
		$context = stream_context_create($options);
		$data = file_get_contents($url, false, $context);
		return $data;
	}
	
	public function deleteMenu() {
		$url = self::MenuUrl.'delete?access_token='.$this->accessTokenManager->getToken();
		return json_decode(file_get_contents($url));
	}
}



?>